import 'dart:math';
import 'package:FlipClock/controller/animation_controller.dart';
import 'package:FlipClock/controller/controller.dart';
import 'package:FlipClock/widgets/flip_card.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class DataHourCard extends StatefulWidget {
  final RxString _timeNow;
  final RxString _timeAge;
  final double _side;
  const DataHourCard(this._timeNow, this._timeAge, this._side) : super();

  @override
  _DataHourCardState createState() => _DataHourCardState();
}

class _DataHourCardState extends State<DataHourCard>
    with TickerProviderStateMixin {
  Controller c = Get.put(Controller());
  FlipAnimationController ac = Get.put(FlipAnimationController());
  Animation _animation;

  @override
  void initState() {
    ac.isTimerAnimationStop = false;
    ac.hController = AnimationController(
        vsync: this, duration: Duration(milliseconds: ac.duration))
      ..addListener(() {
        setState(() {});
      });

    _animation = ac.hController
        .drive(CurveTween(curve: Curves.linear))
        .drive(Tween(begin: .0, end: pi));

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return FlipCard(
      widget._timeNow,
      widget._timeAge,
      _animation,
      widget._side,
      ac.hIndex,
    );
  }

  @override
  void dispose() {
    ac.hController.dispose();
    ac.isDateAniamtionStop = true;
    super.dispose();
  }
}
